package com.xinsoft.entity.dto;

import cn.hutool.core.util.ObjectUtil;
import com.xinsoft.common.exception.BDException;
import com.xinsoft.utils.TokenUtil;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.Objects;
import java.util.UUID;

/**
 * 收料通知新增传参
 */
@Data
public class ErpNoticeBillParam {

    /**
     * 物料ID
     */
    @NotNull(message = "物料ID不能为空")
    private Integer materialId;

    /**
     * 数量
     */
    @NotNull(message = "数量不能为空")
    private BigDecimal qty;

    /**
     * 库存批次
     */
    @NotBlank(message = "批次不能为空")
    private String batch;

    /**
     * 仓库ID
     */
    private Integer warehouseId;

    /**
     * 库位ID
     */
    private Integer warehItemId;

    /**
     * 源单id
     */
    private Integer sourceId;

    /**
     * 源单明细id
     */
    private Integer sourceItemId;

    /**
     * 源单编码
     */
    private String sourceCode;

    /**
     * 采购收料通知：71  委外收料通知：1007105
     */
    private String noticeTypeId;

    public static KisStockInOrOutDto voToPo(ErpNoticeBillParam param) {
        if (param == null) {
            return null;
        }
        KisStockInOrOutDto po = new KisStockInOrOutDto();
        UUID uuid = UUID.randomUUID();
        po.setGUID(uuid.toString());
        po.setSManagerId(TokenUtil.getUserId().toString());
        po.setFManagerId(TokenUtil.getUserId().toString());
        po.setUserId(TokenUtil.getUserId().toString());
        Integer clerkId = TokenUtil.getUser().getClerkId();// 金蝶用户id为空，对接到金蝶的单据将缺少制单人字段->单据无法删除
        if (ObjectUtil.isEmpty(clerkId)){
            throw new BDException("当前用户无法进行当前操作！");
        }
        po.setBillerId(clerkId.toString());
        po.setBATCHNO(param.getBatch());
        po.setItemId(param.getMaterialId().toString());
        po.setQty(param.getQty().toString());
        po.setSecQty(param.getQty().toString());
        po.setDCStockId(param.getWarehouseId().toString());
        po.setDCSPId("0");
        po.setSrcInterId(param.getSourceId().toString());
        po.setSrcEntryId(param.getSourceItemId().toString());
        po.setFOrderBillNo(param.getSourceCode());
        po.setSrcBillNo(param.getSourceCode());
        po.setSrcTranTypeId(param.getNoticeTypeId());
        // po.setSupplyId("");
        return po;
    }

}
